import com.sty.pojo.user;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;

/**
 * @author STY
 * @version 1.0
 * @date 2021/2/22 0:19
 */

public class Main {
    public static void main(String[] args) {
        final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
                .configure() // configures settings from hibernate.cfg.xml
                .build();

        var sessionFactory = new MetadataSources(registry)
                .buildMetadata()
                .buildSessionFactory();
        Session session = sessionFactory.openSession();
        Transaction tx =  session.beginTransaction();
        user _user = new user();
        _user.setName("zhangsan");
        _user.setPwd("12377");
        session.save(_user);
        tx.commit();
        session.close();
    }
}
